package com.woniuxy.stage3demo.service.otherPzc.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.stage3demo.bean.otherPzc.PhoneCheckBean;
import com.woniuxy.stage3demo.mapper.otherPzc.PhoneCheckMapper;
import com.woniuxy.stage3demo.pageHelper.PageRequest;
import com.woniuxy.stage3demo.service.otherPzc.IPhoneCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class PhoneCheckServiceImpl implements IPhoneCheckService {

    @Autowired
    private PhoneCheckMapper phoneCheckMapper;

    /**
     * 新增电核项
     *
     * @param phoneCheck 新增的电核项对象
     * @return 数据库操作的行数
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int savePhoneCheck(PhoneCheckBean phoneCheck) {
        return phoneCheckMapper.savePhoneCheck(phoneCheck);
    }

    /**
     * 删除电核项
     *
     * @param id 删除的电核项对象的id
     * @return 数据库操作的行数
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int deletePhoneCheck(int id) {
        return phoneCheckMapper.deletePhoneCheck(id);
    }

    /**
     * 修改电核项
     *
     * @param phoneCheck 修改的电核项对象
     * @return 操作行数
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int updatePhoneCheck(PhoneCheckBean phoneCheck) {
        return phoneCheckMapper.updatePhoneCheck(phoneCheck);
    }

    /**
     * 分页查询
     *
     * @param request
     * @param phoneCheck
     * @return
     */
    @Override
    public PageInfo<PhoneCheckBean> findAllByParams(PageRequest request, PhoneCheckBean phoneCheck) {
        return PageHelper.startPage(request.getPageNum(),request.getLimit()).
                doSelectPageInfo(()->phoneCheckMapper.findAllByParams(request,phoneCheck));
    }

    /**
     * 查询所有分类
     *
     * @return
     */
    @Override
    public List<String> findAllCategory() {
        return phoneCheckMapper.findAllCategory();
    }

}
